<template>
    <div class="newsinfo-contenter"> 
        <h3 class="title">{{newsinfo.title}}</h3>
        <p class="info">
            <span>发表时间:{{newsinfo.add_time|dataFormat('YYYY-MM-DD')}}</span>
            <span>点击:{{newsinfo.click}}次</span>
        </p>
        <hr>
        <!-- 新闻内容 -->
        <div id="content" v-html="newsinfo.content">

        </div>

        <!-- 评论区 -->
        <!-- 父组件传值给子组件，通过属性绑定 -->
        <comment :newsid="id"></comment>
    </div>
</template>

<script>
//导入Comment.vue子组件
import comment from '../sub-conponents/Comment.vue'

export default {
    data(){
        return {
            newsinfo:{}//新闻列表内容
        };
    },
    methods:{
        //获取新闻信息
        async getNewsinfo(){
           const {data} = await this.$http.get('/api/getnew/'+this.id)
           if(data.status === 0){
               return (this.newsinfo = data.message[0]);
           }
        }
    },
    created(){
        this.getNewsinfo()
    },
    props:['id'],
    components:{//表示注册一个私有子组件，及为评论组件
        comment
    }

}
</script>

<style lang="scss" scoped>
    .newsinfo-contenter{
        padding: 3px;
        .title{
            font-size: 15px;
            text-align: center;
            color: red;
            margin: 15px 0;
        }
        .info{
            color: #26A2FF;
            display: flex;
            justify-content: space-between;
        }
    }
    
</style>